package com.gitee.wsl.unit.angle

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

object AngleUnitSerializer : KSerializer<AngleUnit> {
    override fun deserialize(decoder: Decoder): AngleUnit =
        AngleUnit.Radians(decoder.decodeDouble())

    override fun serialize(
        encoder: Encoder,
        value: AngleUnit,
    ): Unit = encoder.encodeDouble(value.radian)

    override val descriptor: SerialDescriptor =
        PrimitiveSerialDescriptor("AngleUnit", PrimitiveKind.DOUBLE)
}